package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.MesMatbom;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.MesSordProd;
import com.ruoyi.system.service.IMesSordProdService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 销售订单产品Controller
 * 
 * @author ruoyi
 * @date 2024-06-01
 */
@RestController
@RequestMapping("/system/prod")
public class MesSordProdController extends BaseController
{
    @Autowired
    private IMesSordProdService mesSordProdService;

    /**
     * 查询销售订单产品列表
     */
    @PreAuthorize("@ss.hasPermi('system:prod:list')")
    @GetMapping("/list")
    public TableDataInfo list(MesSordProd mesSordProd)
    {
        startPage();
        List<MesSordProd> list = mesSordProdService.selectMesSordProdList(mesSordProd);
        return getDataTable(list);
    }

    /**
     * 导出销售订单产品列表
     */
    @PreAuthorize("@ss.hasPermi('system:prod:export')")
    @Log(title = "销售订单产品", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MesSordProd mesSordProd)
    {
        List<MesSordProd> list = mesSordProdService.selectMesSordProdList(mesSordProd);
        ExcelUtil<MesSordProd> util = new ExcelUtil<MesSordProd>(MesSordProd.class);
        util.exportExcel(response, list, "销售订单产品数据");
    }

    /**
     * 获取销售订单产品详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:prod:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return AjaxResult.success(mesSordProdService.selectMesSordProdById(id));
    }

    /**
     * 新增销售订单产品
     */
    @PreAuthorize("@ss.hasPermi('system:prod:add')")
    @Log(title = "销售订单产品", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MesSordProd mesSordProd)
    {
        return toAjax(mesSordProdService.insertMesSordProd(mesSordProd));
    }

    /**
     * 修改销售订单产品
     */
    @PreAuthorize("@ss.hasPermi('system:prod:edit')")
    @Log(title = "销售订单产品", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MesSordProd mesSordProd)
    {
        return toAjax(mesSordProdService.updateMesSordProd(mesSordProd));
    }

    /**
     * 删除销售订单产品
     */
    @PreAuthorize("@ss.hasPermi('system:prod:remove')")
    @Log(title = "销售订单产品", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(mesSordProdService.deleteMesSordProdByIds(ids));
    }

    /******/
    //查看销售订单拥有那些产品接口
    @GetMapping("/prodIds")
    public AjaxResult selectProdId(@RequestParam("sordId") String sordId) {
        List<String> prodIds = mesSordProdService.selectProdId(sordId);
        return AjaxResult.success(prodIds);
    }

    //修改销售订单产品接口
    @PutMapping("/mes/edit/SordProd")
    public AjaxResult editSordProd(@RequestBody MesSordProd mesSordProd){
        return toAjax(mesSordProdService.editSordProd(mesSordProd));
    }

}
